package cn.imvc.app.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import cn.imvc.app.entities.Goods;
import cn.imvc.app.entities.GoodsSku;
import cn.imvc.data.jpa.repository.IJpqlExecutor;

public interface GoodsSkuRepository extends JpaRepository<GoodsSku, Integer>,IJpqlExecutor<GoodsSku>{
	public List<GoodsSku> findByGoods(Goods goods);
	
	public void deleteByGoods(Goods goods);
	
	public List<GoodsSku> findBySpecNameAndSpecIdAndGoods(String specName,String specId,Goods goods);
	
	@Query("select count(g) from GoodsSku g where g.specId like :specIdStr and g.goods.id = :goodsid")
	int getGoodsSkuBySpecId(@Param("specIdStr")String specIdStr,@Param("goodsid")int goodsid);
	
	@Query("select count(g) from GoodsSku g where g.specId like :specIdStr and g.goods.id = :goodsid and g.state!=2")
	int getGoodsSkuBySpecIdNoMothBall(@Param("specIdStr")String specIdStr,@Param("goodsid")int goodsid);
	
	List<GoodsSku> findByIdIn(int[] array);
	
	@Query("select min(g.points) as price from GoodsSku g where g.goods.id = :id and g.state=3")
	Integer getLowPoints(@Param("id")int id);
}
